import React, {Component} from 'react';
import './index.less';
import {base} from 'nc-lightapp-front';

const {NCModal, NCButton} = base;
const {Header: NCModalHeader, Body: NCModalBody, Footer: NCModalFooter} = NCModal;

class AlertModal extends Component {
    constructor(props) {
        super(props);
        this.state = {
            visible: false,
            message: ''
        };
    }

    show = (msg, callback) => {
        this.setState({
            visible: true,
            message: msg
        });
        this.callback = callback;
    };

    cover = () => {
        this.setState({
            visible: false
        });
        this.callback && this.callback('2')
    };

    notCover = () => {
        this.setState({
            visible: false
        });
        this.callback && this.callback('3')
    };

    cancel = () => {
        this.setState({
            visible: false
        })
    };

    render() {
        const {visible, message} = this.state;
        const {language} = this.props;
        return (
            <NCModal
                show={visible}
                size="sm"
                backdrop={'static'}
            >
                <NCModalHeader>
                    {language['gx6008-000128']}
                </NCModalHeader>
                <NCModalBody>
                    <div
                        dangerouslySetInnerHTML={{
                            __html: message
                        }}
                    />
                </NCModalBody>
                <NCModalFooter>
                    <NCButton colors="primary" onClick={this.cover}>
                        {language['gx6008-000292']}
                    </NCButton>
                    <NCButton shape="border" onClick={this.notCover}>
                        {language['gx6008-000293']}
                    </NCButton>
                    <NCButton shape="border" onClick={this.cancel}>
                        {language['gx6008-000025']}
                    </NCButton>
                </NCModalFooter>
            </NCModal>
        );
    }
}

export default AlertModal;
